package com.zhiyou100.servicrImpl;

import java.util.ArrayList;

import org.springframework.stereotype.Service;

import com.zhiyou100.model.Doctor;
import com.zhiyou100.model.ResponseObject;
import com.zhiyou100.model.User;
import com.zhiyou100.service.AjaxService;
@Service
public class AjaxServiceImpl implements AjaxService{
	/*
	 * 只要不是admin都可注册
	 * 
	 */
	@Override
	public String checkUser(String usernameJson) {
		String code = null;
		if(usernameJson != null && usernameJson != "" &&usernameJson.equals("admin")) {
			code ="{\"code\":\"200\"}";
		}else {
			code = "{\"code\":\"400\"}";
		}
		return code;
	}

	@Override
	public ResponseObject checkUser2(String usernameJson) {
		
		ResponseObject ro = new ResponseObject();
		if(usernameJson == null || usernameJson == "" || usernameJson.equals("admin")) {
			ro.setCode("400");
			ro.setMsg("用户已存在");
		}else {
			ro.setCode("200");
			ro.setMsg("用户可注册");
		}
		System.out.println("业务层返回的结果是: "+ro);
		return ro;
	}
	// 根据id回显信息
	@Override
	public ResponseObject findUserById(String id) {
		User user = new User();
		user.setReal_name("张三");
		user.setPassword("123456");
		user.setEmail("2199981259@qq.com");
		// 创建响应对象
		ResponseObject ro = new ResponseObject("200","回显",user);
		return ro;
	}
	// 二级联动
	@Override
	public ResponseObject teoLevel(String val) {
		ArrayList<Doctor> lists = new ArrayList<>();
		if(val != null && val != "") {
			// 假设科室
			if(val.equals("1")) {
				lists.add(new Doctor("k1张三"));
				lists.add(new Doctor("k1李四"));
				lists.add(new Doctor("k1王五"));
				lists.add(new Doctor("k1赵六"));
			}else if(val.equals("2")) {
				lists.add(new Doctor("k2郭亮亮"));
				lists.add(new Doctor("k2费孝宏"));
				lists.add(new Doctor("k2王东旭"));
				lists.add(new Doctor("k2段宝"));
			}else if(val.equals("3")) {
				lists.add(new Doctor("k3沈秋根"));
				lists.add(new Doctor("k3陈旭"));
				lists.add(new Doctor("k3周文博"));
				lists.add(new Doctor("k3渣渣北"));
			}
		}else {
			System.out.println("id不正确");
		}
		ResponseObject ro = new ResponseObject("200","成功",lists);
		return ro;
	}
}





